package com.ruoyi.ring.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.ring.domain.UserFoodInfo;
import com.ruoyi.ring.domain.dto.GeneralSecondDTO;
import com.ruoyi.ring.mapper.UserFoodInfoMapper;
import com.ruoyi.ring.service.IUserFoodInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 饮食记录Service业务层处理
 * 
 * @author liuwp
 * @date 2025-09-04
 */
@Service
public class UserFoodInfoServiceImpl implements IUserFoodInfoService 
{
    @Resource
    private UserFoodInfoMapper userFoodInfoMapper;

    /**
     * 查询饮食记录
     * 
     * @param id 饮食记录主键
     * @return 饮食记录
     */
    @Override
    public UserFoodInfo selectUserFoodInfoById(Long id)
    {
        return userFoodInfoMapper.selectUserFoodInfoById(id);
    }

    /**
     * 查询饮食记录列表
     * 
     * @param userFoodInfo 饮食记录
     * @return 饮食记录
     */
    @Override
    public List<UserFoodInfo> selectUserFoodInfoList(UserFoodInfo userFoodInfo)
    {
        return userFoodInfoMapper.selectUserFoodInfoList(userFoodInfo);
    }

    /**
     * 根据业务主键查询一条记录：饮食记录
     *
     * @param userFoodInfo 饮食记录
     * @return 饮食记录
     */
    @Override
    public UserFoodInfo selectOneUserFoodInfo(UserFoodInfo userFoodInfo)
    {
        return userFoodInfoMapper.selectOneUserFoodInfo(userFoodInfo);
    }

    /**
     * 新增饮食记录
     * 
     * @param userFoodInfo 饮食记录
     * @return 结果
     */
    @Override
    public int insertUserFoodInfo(UserFoodInfo userFoodInfo)
    {
        userFoodInfo.setCreateTime(DateUtils.getNowDate());
        return userFoodInfoMapper.insertUserFoodInfo(userFoodInfo);
    }

    /**
     * 修改饮食记录
     * 
     * @param userFoodInfo 饮食记录
     * @return 结果
     */
    @Override
    public int updateUserFoodInfo(UserFoodInfo userFoodInfo)
    {
        userFoodInfo.setUpdateTime(DateUtils.getNowDate());
        return userFoodInfoMapper.updateUserFoodInfo(userFoodInfo);
    }

    @Override
    public int updateUserFoodInfoCondition(UserFoodInfo userFoodInfo, UserFoodInfo userFoodInfoCondition)
    {
                userFoodInfo.setUpdateTime(DateUtils.getNowDate());
        return userFoodInfoMapper.updateUserFoodInfoCondition(userFoodInfo, userFoodInfoCondition);
    }

    /**
     * 批量删除饮食记录
     * 
     * @param ids 需要删除的饮食记录主键
     * @return 结果
     */
    @Override
    public int deleteUserFoodInfoByIds(Long[] ids)
    {
        return userFoodInfoMapper.deleteUserFoodInfoByIds(ids);
    }

    /**
     * 删除饮食记录信息
     * 
     * @param id 饮食记录主键
     * @return 结果
     */
    @Override
    public int deleteUserFoodInfoById(Long id)
    {
        return userFoodInfoMapper.deleteUserFoodInfoById(id);
    }

    /**
     * 条件删除饮食记录
     *
     * @param userFoodInfo 饮食记录
     * @return 结果
     */
    @Override
    public int deleteUserFoodInfoByCondition(UserFoodInfo userFoodInfo)
    {
        return userFoodInfoMapper.deleteUserFoodInfoByCondition(userFoodInfo);
    }

    @Override
    public List<UserFoodInfo> queryUserFoodList(GeneralSecondDTO secondDTO) {
        return userFoodInfoMapper.queryUserFoodList(secondDTO).stream().limit(5).collect(Collectors.toList());
    }

}
